<?php
class CGetpass extends Zend_Db_Table
{
	protected $_name;
	protected $_primary;

	public function __construct()
	{
		$this->_name = R_PRE."getpass";
		$this->_primary = "id";
		parent::__construct();
		
	}

	public function add($data)
	{
		$id=$this->insert($data);		
		return $id;
	}
	
	public function setInvalid($hash)
	{
		$db = $this->getAdapter();
		$where = $db->quoteInto('hash = ?', $hash);
		return $this->update(array('isValid'=>0), $where);
	}
	
	public function genHash($username, $uid)
	{
		return md5($username . $uid . time());
	}
	
	public function resetPass($uid, $newPass)
	{
		$member = new CMember();
        $userArray = $member->getUserDetails(array('uid'=>$uid));
        if (empty($userArray)) {
        	return false;
        }
        
        return $member->updateUserDetail(
                array(
                'userpass'=>$newPass,
                ),
                array('uid'=>$uid)
        );
	}
}